package MultiThread;

public class RecorderExample implements Runnable{
    private int x = 0;
    private boolean flag = false;

    public void writer() {
        x = 42;
        flag = true;
    }

    public void reader() {
        if(flag) {
            System.out.println(x);
        }
    }

    public static void main(String[] args) {
        RecorderExample r = new RecorderExample();

        new Thread(r).start();
        new Thread(r).start();
    }

    @Override
    public void run() {
        writer();
        reader();
    }
}
